<template>
	<div class="right-box">
		<Breadcrumb  style="margin-bottom: 5px;">
	        <BreadcrumbItem>
	            <Icon type="ios-archive" color="red" size="18"></Icon> 仓库作业
	        </BreadcrumbItem>
	        <BreadcrumbItem>
	           资源申请
	        </BreadcrumbItem>
	    </Breadcrumb>
	    <Table height="480" :columns="columns1" :data="datas">
    		<template slot-scope="{ row, index }" slot="action">
	           	<Button type="primary" @click="edit(row)"  v-if="userType==0 && row.status==0">同意</Button>
	           	<Button type="error"  @click="refuce(row)"  v-if="userType==0 && row.status==0">拒绝</Button>
	        </template>
	    	<template slot-scope="{row,index}" slot="status">
	    		<span v-if="row.status == 0">待处理</span>
	    		<span v-if="row.status == 1">
	    			已批准
	    		</span>
	    		<span v-if="row.status == 2">
	    			已拒绝
	    		</span>
	    	</template>
	    </Table>
	</div>
</template>

<script>
	export default{
		name:'moveManager',
		data(){
			return{
				userType:'',
				columns1: [//表头
                    {
                        title: '申报编号',
                        key: 'recordId'
                    },
                    {
                        title: '申报内容',
                        key: 'recordItemName'
                    },{
                    	title:'申报数量',
                    	key:'recordItemCount'
                    },{
                    	title:'所属仓库',
                    	key:'recordWarehouseName'
                    },{
                    	title:'申请时间',
                    	key:'createTime'
                    },{
                    	title:'状态',
                    	key:'status',
                    	slot:'status'
                    },
                    {
                    	title:'操作',
                    	slot:'action'
                    }
                ],
				datas:[],//表格数据
			}
		},
		methods:{
			//同意
			edit(row){
				let that = this
				this.$axios({
	    			method:'post',
	    			url:that.GLOBAL.url+'/sys/modifyItemRecordStatus',
	    			data:{
	    				itemRecordId:row.recordId,
	    				status:'1'
	    			},
	    			transformRequest:[function(data){
	    				let ret = ''
	    				for(let it in data){
	    					ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
	    				}
	    				return ret
	    			}],
	    			xhrFields:{
	    				widthCredentials:true
	    			},
	    			crossDomain:true,
	    			header:{
	    				'Content-Type': 'application/x-www-form-urlencoded'
	    			}
	    		}).then(res=>{
	    			console.log(res)
	    			if(res.data.code == 200){
	    				this.getApply()
	    			}else{
	    				this.$Message.error(res.data.msg)
	    			}
	    		}).catch(function(err){
	    			console.log(err)
	    		})
			},
			//拒绝
			refuce(row){
				let that = this
				this.$axios({
	    			method:'post',
	    			url:that.GLOBAL.url+'/sys/modifyItemRecordStatus',
	    			data:{
	    				itemRecordId:row.recordId,
	    				status:'2'
	    			},
	    			transformRequest:[function(data){
	    				let ret = ''
	    				for(let it in data){
	    					ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
	    				}
	    				return ret
	    			}],
	    			xhrFields:{
	    				widthCredentials:true
	    			},
	    			crossDomain:true,
	    			header:{
	    				'Content-Type': 'application/x-www-form-urlencoded'
	    			}
	    		}).then(res=>{
	    			if(res.data.code == 200){
	    				this.getApply()
	    			}else{
	    				this.$Message.error(res.data.msg)
	    			}
	    		}).catch(function(err){
	    			console.log(err)
	    		})
			},
			getApply(){//获取申请记录
				let that = this
				this.$axios({
	    			method:'post',
	    			url:that.GLOBAL.url+'/sys/getItemRecord',
	    			data:{
	    			},
	    			transformRequest:[function(data){
	    				let ret = ''
	    				for(let it in data){
	    					ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
	    				}
	    				return ret
	    			}],
	    			xhrFields:{
	    				widthCredentials:true
	    			},
	    			crossDomain:true,
	    			header:{
	    				'Content-Type': 'application/x-www-form-urlencoded'
	    			}
	    		}).then(res=>{
	    			console.log(res)
	    			this.datas = res.data.itemRecordList
	    		}).catch(function(err){
	    			console.log(err)
	    		})
			},
		},
		created(){
			this.userType=this.LS.getLS('userType')
			this.getApply()
		}
	}
</script>

<style scoped>
.right-box{
	width: 100%;
	height: 100%;
	position: relative;
}
.addBtn{
	position: absolute;
	top: -10px;
	right: 20px;
}
.page-nav{
	width: 100%;
	display: -webkit-flex;
	display: -ms-flexbox;
	display: -moz-box;
	display: flex;
	justify-content: center;
	align-content: center;
	margin-top: 10px;
}
.search-input{
	width:40%;
	position: absolute;
	top: -10px;
	left: 50%;
	transform: translateX(-50%);
	-webkit-transform: translateX(-50%);
}
</style>